package day13.problem2;

import java.util.*;

//最长无重复子数组
//https://www.nowcoder.com/practice/b56799ebfd684fb394bd315e89324fb4?tpId=196&tqId=37149&ru=/exam/oj


public class Solution {
    public int maxLength (int[] arr) {
        int n = arr.length, ret = 0;
        HashMap<Integer, Integer> map = new HashMap<>();
        for(int i = 0, j =0; j<n; j++) {
            map.put(arr[j], map.getOrDefault(arr[j], 0) + 1);
            while(map.get(arr[j]) > 1) {
                map.put(arr[i], map.get(arr[i]) - 1);
                i++;
            }
            ret = Math.max(ret, j - i + 1);
        }

        return ret;
    }
}